
//
//  HomeCell.m
//  筛选框
//
//  Created by songhuipan on 16/6/26.
//  Copyright © 2016年 songhuipan. All rights reserved.
//

#import "HomeCell.h"
#import "UIView+PullView.h"
#import "SiftView.h"
#import "UIView+Frame.h"
static NSString *const tableViewCellId = @"tableViewCellId";
@interface HomeCell ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)SiftView *siftView;
@property (nonatomic,assign)CGFloat contentoffsetY;
@end
@implementation HomeCell
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeSiftViewHeight) name:@"siftViewChangeHeight" object:nil];
    
        dispatch_async(dispatch_get_main_queue(), ^{
    
            
            [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:tableViewCellId];
            
            [self.contentView addSubview:self.tableView];
            [self.contentView addSubview:self.siftView];
        });
    }
    return self;
}
- (void)changeSiftViewHeight {
    self.siftView.h = self.h;
}
- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.w, self.h-44) style:UITableViewStylePlain];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.w, 44)];
        _tableView.bounces = NO;
    }
    return _tableView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 30;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableViewCellId];
    cell.textLabel.text = @(indexPath.row).stringValue;
    return cell;
}
- (SiftView *)siftView {
    if (!_siftView) {
        _siftView = [[SiftView alloc]initWithFrame:CGRectMake(0, 0, self.w, 44)];
    }
    return _siftView;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView.contentOffset.y>self.contentoffsetY) {
        self.siftView.isScrollToTop = YES;
    }else {
        self.siftView.isScrollToTop = NO;
    }
    self.contentoffsetY = scrollView.contentOffset.y;
}
- (void)dealloc {
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
@end




















